package com.ecommerce.model;

public class CartItem {
    private int id;
    private int userId;
    private int productId;
    private String productName;
    private double productPrice;
    private int quantity;

    public CartItem() {}

    public CartItem(int userId, int productId, int quantity) {
        this.userId = userId;
        this.productId = productId;
        this.quantity = quantity;
    }

    // Getters and Setters
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }

    public int getUserId() { return userId; }
    public void setUserId(int userId) { this.userId = userId; }

    public int getProductId() { return productId; }
    public void setProductId(int productId) { this.productId = productId; }

    public String getProductName() { return productName; }
    public void setProductName(String productName) { this.productName = productName; }

    public double getProductPrice() { return productPrice; }
    public void setProductPrice(double productPrice) { this.productPrice = productPrice; }

    public int getQuantity() { return quantity; }
    public void setQuantity(int quantity) { this.quantity = quantity; }

    public double getSubtotal() {
        return productPrice * quantity;
    }

    @Override
    public String toString() {
        return String.format("商品: %s | 单价: ¥%.2f | 数量: %d | 小计: ¥%.2f",
                productName, productPrice, quantity, getSubtotal());
    }
}
